package com.gitee.wsl.coroutines.executor.sample

import com.gitee.wsl.concurrent.api.SuspendRunnableWithResult
import com.gitee.wsl.coroutines.executor.SuspendKExecutor
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock

class QueueExecutor(private val mutex: Mutex = Mutex()): SuspendKExecutor {
     override suspend fun <T> executeSuspend(block: SuspendRunnableWithResult<T>): T {
        mutex.withLock {
            return block.run()
        }
    }

    companion object{
        val INSTANCE = QueueExecutor()
    }
}